﻿using System;
using System.Diagnostics;
using System.Net;

using NUnit.Framework;

using octalforty.Chinchillin.Agent.Core.Tracing.Impl;
using octalforty.Chinchillin.Shared.Deployment;
using octalforty.Chinchillin.Shared.Deployment.Agent;

using Rhino.Mocks;

namespace octalforty.Chinchillin.Tests.Core.Tracing
{
    [TestFixture()]
    public class TracingManagerServiceTestFixture
    {
        [Test()]
        public void TraceEvent()
        {
            var mocks = new MockRepository();

            var deploymentCallback = mocks.StrictMock<IDeploymentCallback>();
            var context = new ActionExecutionContext(null, false, TraceEventType.Verbose);

            using(mocks.Record())
            {
                Expect.Call(() => deploymentCallback.TraceEvent(Dns.GetHostName(), DateTime.Today, TraceEventType.Error, 0, "Error")).
                    IgnoreArguments();
            } // using

            var tracingManager = new TracingManagerService { DeploymentCallback = deploymentCallback };

            tracingManager.TraceEvent(context, TraceEventType.Error, 0, "Error");

            mocks.VerifyAll();
        }

        [Test()]
        public void TraceEventFiltersEvents()
        {
            var mocks = new MockRepository();

            var deploymentCallback = mocks.StrictMock<IDeploymentCallback>();
            var context = new ActionExecutionContext(null, false, TraceEventType.Verbose);

            using(mocks.Record())
            {
            } // using

            var tracingManager = new TracingManagerService { DeploymentCallback = deploymentCallback };

            tracingManager.TraceEvent(context, TraceEventType.Start, 0, "Error");

            mocks.VerifyAll();
        }
    }
}
